/*
 * AgendaApp.java
 */
package GUI;

import PureFactoryClasses.ApController;
import FMK_SEK.Base.SecurityFramework;
import FMK_SEK.DefaultImplementations.CreadorXML;
import SeguridadImplementada.CreadorUsuarioAgenda;
import Utilidades.Settings;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class AgendaApp extends SingleFrameApplication {

    Login login;

    /**
     * At startup create and show the main frame of the application.
     */
    @Override
    protected void startup() {
        SecurityFramework securityFMK = SecurityFramework.getInstance();

        //Seleccionamos el modo de login (XML / DB)
        if (Settings.getInstance().getUserData().toLowerCase().equals("xml")) {
            // Inicializacion con el login XML
            securityFMK.inicializar(new CreadorXML(), Application.getInstance().getContext().getLocalStorage().getDirectory().getAbsolutePath(), 60 * 15);
        } else {
            //A continuacion esta el codigo para inicializar el framework de seguridad con la clase de este proyecto (usando la DB).
            securityFMK.inicializar(new CreadorUsuarioAgenda(),
                    Application.getInstance().getContext().getLocalStorage().getDirectory().getAbsolutePath(), 60 * 15);
        }
        login = new Login();
        show(login);
    }

    public void mostrarPrincipal() {
        login.dispose();
        login = null;
        ApController.getInstance().inicializarAplicacion();
        show(new AgendaView(this));
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override
    protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of AgendaApp
     */
    public static AgendaApp getApplication() {
        return Application.getInstance(AgendaApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(AgendaApp.class, args);
    }
}
